﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace wpf.Triage.Convert
{
    public class RadioCheckConvert : IValueConverter
    {
        /// <summary>
        /// 单选框参数值比较勾选转换器  2022-02-21
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return false;
            }
            if (parameter!= null)
            {
                if (value.ToString().Equals(parameter.ToString()))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }else
            {
                return false;
            }
        }
        /// <summary>
        /// 接口实现 2022-02-21
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool bl && bl)
            {
                return parameter;
            }
            return DependencyProperty.UnsetValue;
        }
    }
}
